package benny.ApkposStore.Xml;

import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import benny.ApkposStore.model.Room;
import benny.ApkposStore.model.Turndate;

public class turnlistContentHandler extends DefaultHandler {
	private List<Turndate> turndates = null;
	private Turndate turndate = null;
	private String tagname = null;

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		// TODO Auto-generated method stub
		String temp = new String(ch, start, length);
		if (tagname.equals("id")) {
			turndate.setId(temp);

		} else if (tagname.equals("turn.item")) {
			turndate.setTurn_item(temp);

		} else if (tagname.equals("turn.num")) {
			turndate.setTurn_num(temp);
		} else if (tagname.equals("turn.total")) {
			turndate.setTurn_total(temp);
		} 

	}

	public List<Turndate> getInfos() {
		return turndates;
	}

	public void setInfos( List<Turndate> turndates) {
		this.turndates = turndates;
	}

	public turnlistContentHandler(List<Turndate> turndates) {
		super();
		this.turndates = turndates;
	}

	@Override
	public void endDocument() throws SAXException {
		// TODO Auto-generated method stub
					
		}
	

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if (qName.equals("turn")){
			turndates.add(turndate);
		}
		tagname = "";
	}

	@Override
	public void startDocument() throws SAXException {
		// TODO Auto-generated method stub
		super.startDocument();
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		this.tagname = localName;
		if (tagname.equals("turn")) {
			turndate = new Turndate();
		}

	}

}
